﻿function keyLogin() {
    //回车键的键值为13
    if (event.keyCode === 13) {
        //调用登录按钮的登录事件
        document.getElementById("login_form").submit();
    }
}

function myBrowser() {
    //取得浏览器的userAgent字符串
    var userAgent = navigator.userAgent;
    //判断是否Opera浏览器
    var isOpera = userAgent.indexOf("Opera") > -1;
    if (isOpera) {
        return "Opera"
    }
    //判断是否Firefox浏览器
    if (userAgent.indexOf("Firefox") > -1) {
        return "FF";
    }

    if (userAgent.indexOf("Chrome") > -1) {
        return "Chrome";
    }

    //判断是否Safari浏览器
    if (userAgent.indexOf("Safari") > -1) {
        return "Safari";
    }

    //判断是否IE浏览器
    if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
        return "IE";
    }

    if (!!window.ActiveXObject || "ActiveXObject" in window) {
        return "IE";
    }
}

function showdiv() {
    document.getElementById("bg").style.display = "block";
    document.getElementById("show").style.display = "block";
}

function hidediv() {
    document.getElementById("bg").style.display = 'none';
    document.getElementById("show").style.display = 'none';
}

function ukeylogin() {
    var mb = myBrowser();
    if ("IE" != mb) {
        alert("U-key登录只支持IE浏览器");
        return;
    }
    showdiv();
    try {
        var lRet = initXaca('XACA', "", "");
        if (lRet != 0) {
            hidediv();
            return false;
        }

    } catch (e) {
        alert('请确保电脑安装证书小精灵插入UKey！');
    }
    var signCert = GetCert(SIGN_TYPE);
    var info = GetCertInfo(signCert, X509_CERT_SUBJECT_CN);
    var signdata = SignDataByP7(GenRandom(16), ks_hash_alg);
    if (signdata == '' || typeof(signdata) == 'undefined') {
        alert("签名失败");
        hidediv();
        return false;
    } else {
        var ret = XacaVerifyP7SignData(signdata);
        alert("info==>"+info);
        if (ret == 0) {
            alert(info);
            document.getElementById("ukey").value = info;
            document.login_form.action = "<%=basePath%>admin/loginByUkey.jspx";
            document.getElementById("login_form").submit();
        }
    }
    setTimeout("hidediv()", 3000);
}